package com.intelligent.system.auth.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.system.auth.dto.ContactDTO;
import com.intelligent.system.auth.dto.ContactQueryDTO;
import com.intelligent.system.auth.entity.Contact;
import com.intelligent.system.auth.service.ContactService;
import com.intelligent.system.common.response.ResultDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 联系人控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/contacts")
@Api(tags = "联系人管理接口")
public class ContactController {

    @Resource
    private ContactService contactService;

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取联系人")
    public ResultDO<ContactDTO> getById(
            @ApiParam(value = "联系人ID", required = true)
            @PathVariable Long id) {
        return contactService.getContactById(id);
    }


    @GetMapping("/organization/{organizationId}")
    @ApiOperation("根据组织ID获取联系人列表")
    public ResultDO<List<ContactDTO>> listByOrganizationId(
            @ApiParam(value = "组织ID", required = true)
            @PathVariable Long organizationId) {
        return contactService.listByOrganizationId(organizationId);
    }

    @PostMapping("/page")
    @ApiOperation("分页查询联系人")
    public ResultDO<IPage<ContactDTO>> page(
            @ApiParam(value = "查询参数", required = true)
            @Validated @RequestBody ContactQueryDTO queryDTO) {
        return contactService.page(queryDTO);
    }

    @PostMapping("/add")
    @ApiOperation("新增联系人")
    public ResultDO<?> save(
            @ApiParam(value = "联系人信息", required = true)
            @RequestBody ContactDTO contactDTO) {
        return contactService.save(contactDTO);
    }

    @PostMapping("/update")
    @ApiOperation("更新联系人")
    public ResultDO<?> update(
            @ApiParam(value = "联系人信息", required = true)
            @RequestBody ContactDTO contactDTO) {
        return contactService.update(contactDTO);
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("删除联系人")
    public ResultDO<?> deleteById(
            @ApiParam(value = "联系人ID", required = true)
            @PathVariable Long id) {
        return contactService.deleteById(id);
    }

    @GetMapping("/mobile/{mobile}")
    @ApiOperation("根据手机号查询联系人")
    public ResultDO<ContactDTO> getByMobile(
            @ApiParam(value = "手机号", required = true)
            @PathVariable String mobile) {
        return contactService.getByMobile(mobile);
    }

} 